package com.powernode.util;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * Redis操作类
 */
@Component
public class RedisUtil {

    @Resource()
    private StringRedisTemplate stringRedisTemplate;

    // Token存入Redis中的值以Hash方式存储
    public boolean setHashValues(String key, Map<String, String> data, int timeout) {
        boolean result = false;
        // redis添加token数据
        stringRedisTemplate.opsForHash().putAll(key, data);
        if (timeout > 0) {
            // 设置过期时间
            result = stringRedisTemplate.expire(key, timeout, TimeUnit.MINUTES);
        }
        return result;
    }
}
